home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1994 November / Cd Ware (Nro. 2) - Epimundo.iso / DOS / PG / PCLP41.ZIP / MODEM_IO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-03-23  |  3.5 KB  |  135 lines

  1. (*********************************************)
  2. (*                                           *)
  3. (*  Talks to your modem. Called by TERM.PAS  *)
  4. (*                                           *)
  5. (*  This program is donated to the Public    *)
  6. (*  Domain by MarshallSoft Computing, Inc.   *)
  7. (*  It is provided as an example of the use  *)
  8. (*  of the Personal Communications Library.  *)
  9. (*                                           *)
  10. (*********************************************)
  11.  
  12. unit Modem_IO;
  13.  
  14. interface
  15.  
  16. type
  17.   String80 = String[80];
  18.  
  19. procedure SendTo( Port:Integer; TheString:String80);
  20. function  WaitFor(Port:Integer; TheString:String80; WaitTics:Integer):Boolean;
  21. function  DialPhone(Port:Integer; TheString:String80): Boolean;
  22.  
  23. implementation
  24.  
  25. uses PCL4P;
  26.  
  27. function BreakTest : Boolean;
  28. begin
  29.   if SioBrkKey then
  30.     begin
  31.       WriteLn('User BREAK');
  32.       BreakTest := TRUE
  33.     end
  34.   else BreakTest := FALSE;
  35. end;
  36.  
  37.  
  38. procedure SendTo( Port: Integer; TheString:String80);
  39. const CR = 13;
  40. var
  41.    rc : Integer;
  42.    i  : Integer;
  43.    c  : Char;
  44. begin
  45.    rc := SioRxFlush(Port);
  46.    rc := SioDelay(4);
  47.    for i := 1 to Length(TheString) do
  48.       begin
  49.          c := UpCase(TheString[i]);
  50.          case c of
  51.             '!' : c := chr(CR);
  52.             '~' : begin
  53.                      (* delay 1/2 second *)
  54.                      rc := SioDelay(9);
  55.                      c := ' '
  56.                   end;
  57.              ' ': rc := SioDelay(3);
  58.          end;
  59.          (* transmit as 7 bit char *)
  60.          rc := SioPutc(Port, chr(ord(c) and $7f));
  61.          (* wait 3/18th of a second *)
  62.          rc := SioDelay(3);
  63.          (* wait 1 second for echo *)
  64.          rc := SioGetc(Port,18);
  65.          if rc > 0 then Write(chr(rc));
  66.       end (* for *)
  67. end; (* SendTo *)
  68.  
  69. function WaitFor(Port:Integer; TheString:String80; WaitTics:Integer): Boolean;
  70. label WaitForExit;
  71. const
  72.   CR = 13;
  73.   LF = 10;
  74. var
  75.   Code : Integer;
  76.   c : Char;
  77.   i : Integer;
  78.   rc: Integer;
  79.  
  80. function GetModemChar(Port:Integer; Tics:Integer): Integer;
  81. var Code : integer;
  82. begin
  83.   repeat
  84.     if BreakTest then exit;
  85.     (* get next incoming character *)
  86.     Code := SioGetc(Port,Tics);
  87.   until (Code>=0) and (Code <> CR) and (Code <> LF);
  88.   GetModemChar := Code;
  89. end; (* GetModemChar *)
  90.  
  91. begin (* WaitFor *)
  92.   Write( chr(CR) );
  93.   Write( chr(LF) );
  94.   for i:= 1 to Length(TheString) do
  95.     begin
  96.        (* control-BREAK ? *)
  97.        if BreakTest then exit;
  98.        (* c is expected character *)
  99.        c := UpCase( TheString[i] );
  100.        (* wait for next character *)
  101.        if i = 1 then Code := GetModemChar(Port,WaitTics)
  102.        else Code := GetModemChar(Port,18);
  103.        (* echo character from modem *)
  104.        Write(chr(Code));
  105.        (* character must match *)
  106.        if (Code=-1) or (chr(Code) <> c) then
  107.           begin
  108.              writeln('Expecting ',c,' not ',chr(Code),'[',Code,']');
  109.              WaitFor := FALSE;
  110.              goto WaitForExit;
  111.           end
  112.     end; (* for i *)
  113.   (* all characters match *)
  114.   WaitFor := TRUE;
  115. WaitForExit: end; (* WaitFor *)
  116.  
  117. function DialPhone(Port:Integer; TheString:String80): Boolean;
  118. const CR = 13;
  119. var
  120.   Code : Integer;
  121.   Temp : String80;
  122. begin
  123.   Write('...DIALING ');
  124.   WriteLn(TheString);
  125.   Temp := '!!ATDT' + TheString + '!';
  126.   SendTo(Port,Temp);
  127.   (* wait up to 60 seconds for CONNECT *)
  128.   if WaitFor(Port,'CONNECT',60*18) then
  129.     begin
  130.       Code := SioPutc(Port, chr(CR));
  131.       DialPhone := TRUE;
  132.     end;
  133.   DialPhone := FALSE;
  134. end; (* DialPhone *)
  135. end.